package com.example.elemboot.Controller;

import com.example.elemboot.Dao.IBusiness;
import com.example.elemboot.Dao.IFood;
import com.example.elemboot.Entity.Business;
import com.example.elemboot.Entity.Food;
import com.example.elemboot.Utils.AuthAccess;
import com.example.elemboot.Utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/food")
public class FoodController {

    @Resource
    private IFood foodDao;

    @Resource
    private IBusiness businessDao;

    @GetMapping(value = "/listFoodByBusinessId/{businessId}")
    public Result getBusinessById(@PathVariable("businessId") Integer businessId){
        try {
            Business business = businessDao.findById(businessId).get();
            List<Food> foods = foodDao.findFoodsByBusinessEquals(business);
            return Result.success(foods);
        }catch (Exception e){
            return Result.error();
        }
    }
}
